import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import './index.less'

import { AtTextarea }  from 'taro-ui'
import api from '../../service/api';

export default class Feedback extends Taro.Component {

  config = {
    navigationBarTitleText: '意见反馈'
  }

  constructor() {
    super(...arguments)
    this.state = {
      feedbackText:'',
      evenPoint:true
    }
  }

  componentDidMount() {

   }

  pushFeedback(){

      if(this.state.evenPoint == false){
        return false
      }

     if(this.state.feedbackText.length > 6 && this.state.evenPoint == true){
      let params = {}
      let that = this
      params.feedbackContent = this.state.feedbackText
      params.userId = Taro.getStorageSync('loginInfo').userId

      this.setState({
        evenPoint:false
      })

      api.post('/inquiry/save/feedBack', params).then(res => {
        if(res.data.status == '200'){
          Taro.showToast({
            title: '发送成功',
            icon:'success',
            duration: 2000
          })

          setTimeout(()=>{
            Taro.navigateTo({
              url:`/pages/UserCenter/index`
            })
            that.setState({
              evenPoint:true
            })
          },1000)

        }else{
          Taro.showToast({
            title: res.data.msg,
            icon:'none',
            duration: 2000
          })
        }
      })
     }else{
      Taro.showToast({
        title: '最少输入6个字符',
        icon:'none',
        duration: 2000
      })
     }
  }

  handleChange(e){
    this.setState({
      feedbackText:e.target.value
    })
  }


  render() {
    return (
      <View className='page'>
        <View className='page-top'>

        </View>
        <View className='page-main'>
          <AtTextarea
           value={this.state.feedbackText}
           onChange={this.handleChange.bind(this)}
           maxlength='500'
           minlength='6'
           height='300'
           placeholder='请输入你要反馈的内容'
          ></AtTextarea>
        </View>
        <View className='page-bottom'>
          <View className='page-bottom-btn' onClick={this.pushFeedback.bind(this)}>
            <View>
              提交
            </View>
          </View>
        </View>
      </View>
    )
  }
}
